From 558998054287462db06fd7ded77452834be2e108 Mon Sep 17 00:00:00 2001 From: tsteven4 <13596209+tsteven4@users.noreply.github.com> Date: Thu, 20 Apr 2023 18:07:54 -0600 Subject: [PATCH] introduce route_head::empty() (#1074) --- defs.h | 1 + garmin_txt.cc | 4 ++-- gdb.cc | 9 ++++----- gtm.cc | 4 ++-- humminbird.cc | 4 ++-- kml.cc | 12 ++++++------ osm.cc | 2 +- ozi.cc | 2 +- position.cc | 2 +- trackfilter.cc | 8 ++++---- 10 files changed, 24 insertions(+), 24 deletions(-) diff --git a/defs.h b/defs.h index c4b68a2e0..c255e5b76 100644 --- a/defs.h +++ b/defs.h @@ -647,6 +647,7 @@ public: ~route_head(); int rte_waypt_ct() const {return waypoint_list.count();} /* # waypoints in waypoint list */ + bool rte_waypt_empty() const {return waypoint_list.empty();} }; using route_hdr = void (*)(const route_head*); diff --git a/garmin_txt.cc b/garmin_txt.cc index ed5b19c3e..24d7e4dd3 100644 --- a/garmin_txt.cc +++ b/garmin_txt.cc @@ -614,7 +614,7 @@ route_disp_hdr_cb(const route_head* rte) cur_info = &route_info[route_idx]; cur_info->prev_wpt = nullptr; cur_info->total = 0; - if (rte->rte_waypt_ct() <= 0) { + if (rte->rte_waypt_empty()) { return; } @@ -668,7 +668,7 @@ track_disp_hdr_cb(const route_head* track) cur_info = &route_info[route_idx]; cur_info->prev_wpt = nullptr; cur_info->total = 0; - if (track->rte_waypt_ct() <= 0) { + if (track->rte_waypt_empty()) { return; } diff --git a/gdb.cc b/gdb.cc index b42b53604..7ba6bd6ca 100644 --- a/gdb.cc +++ b/gdb.cc @@ -79,7 +79,6 @@ #define DBG(a,b) if ((GDB_DEBUG & (a)) && (b)) -#define ELEMENTS(a) a->rte_waypt_ct() #define NOT_EMPTY(a) (a && *a) void @@ -1404,7 +1403,7 @@ GdbFormat::write_route(const route_head* rte, const QString& rte_name) route_compute_bounds(rte, &bounds); route_write_bounds(&bounds); - int points = ELEMENTS(rte); + int points = rte->rte_waypt_ct(); FWRITE_i32(points); int index = 0; @@ -1513,7 +1512,7 @@ GdbFormat::write_route(const route_head* rte, const QString& rte_name) void GdbFormat::write_track(const route_head* trk, const QString& trk_name) { - int points = ELEMENTS(trk); + int points = trk->rte_waypt_ct(); FWRITE_CSTR(trk_name); FWRITE_C(0); @@ -1665,7 +1664,7 @@ GdbFormat::write_waypoint_cb(const Waypoint* refpt) void GdbFormat::write_route_cb(const route_head* rte) { - if (ELEMENTS(rte) <= 0) { + if (rte->rte_waypt_empty()) { return; } @@ -1687,7 +1686,7 @@ GdbFormat::write_route_cb(const route_head* rte) void GdbFormat::write_track_cb(const route_head* trk) { - if (ELEMENTS(trk) <= 0) { + if (trk->rte_waypt_empty()) { return; } diff --git a/gtm.cc b/gtm.cc index 9460737d9..d2bf5fbfe 100644 --- a/gtm.cc +++ b/gtm.cc @@ -425,7 +425,7 @@ gtm_rd_deinit() static void count_track_styles(const route_head* rte) { - if (rte->rte_waypt_ct() > 0) { + if (!rte->rte_waypt_empty()) { ts_count++; } } @@ -679,7 +679,7 @@ static void write_trk_waypt(const Waypoint* wpt) static void write_trk_style(const route_head* trk) { - if (trk->rte_waypt_ct() > 0) { + if (!trk->rte_waypt_empty()) { fwrite_string(file_out, trk->rte_name); fwrite_byte(file_out, 1); fwrite_long(file_out, 0); diff --git a/humminbird.cc b/humminbird.cc index 6f80e4af5..cdf807370 100644 --- a/humminbird.cc +++ b/humminbird.cc @@ -686,7 +686,7 @@ HumminbirdHTFormat::humminbird_track_head(const route_head* trk) trk_head = nullptr; last_time = 0; - if (trk->rte_waypt_ct() > 0) { + if (!trk->rte_waypt_empty()) { trk_head = (humminbird_trk_header_t*) xcalloc(1, sizeof(humminbird_trk_header_t)); trk_points = (humminbird_trk_point_t*) xcalloc(max_points, sizeof(humminbird_trk_point_t)); @@ -817,7 +817,7 @@ void HumminbirdFormat::humminbird_rte_head(const route_head* rte) { humrte = nullptr; - if (rte->rte_waypt_ct() > 0) { + if (!rte->rte_waypt_empty()) { humrte = (humminbird_rte_t*) xcalloc(1, sizeof(*humrte)); } } diff --git a/kml.cc b/kml.cc index 978b88071..3a1b71a54 100644 --- a/kml.cc +++ b/kml.cc @@ -242,7 +242,7 @@ void KmlFormat::trk_coord(xg_string args, const QXmlStreamAttributes* /*attrs*/) if (wpt_timespan_begin.isValid() && wpt_timespan_end.isValid()) { // If there are some Waypoints, then distribute the TimeSpan to all Waypoints - if (trk_head->rte_waypt_ct() > 0) { + if (!trk_head->rte_waypt_empty()) { qint64 timespan_ms = wpt_timespan_begin.msecsTo(wpt_timespan_end); if (trk_head->rte_waypt_ct() < 2) { fatal(MYNAME ": attempt to interpolate TimeSpan with too few points."); @@ -656,7 +656,7 @@ void KmlFormat::kml_output_header(const route_head* header, const computed_trkda writer->writeOptionalTextElement(QStringLiteral("name"), header->rte_name); kml_output_trkdescription(header, td); - if (export_points && header->rte_waypt_ct() > 0) { + if (export_points && !header->rte_waypt_empty()) { // Put the points in a subfolder writer->writeStartElement(QStringLiteral("Folder")); writer->writeTextElement(QStringLiteral("name"), QStringLiteral("Points")); @@ -874,12 +874,12 @@ void KmlFormat::kml_output_point(const Waypoint* waypointp, kml_point_type pt_ty void KmlFormat::kml_output_tailer(const route_head* header) { - if (export_points && header->rte_waypt_ct() > 0) { + if (export_points && !header->rte_waypt_empty()) { writer->writeEndElement(); // Close Folder tag } // Add a linestring for this track? - if (export_lines && header->rte_waypt_ct() > 0) { + if (export_lines && !header->rte_waypt_empty()) { bool needs_multigeometry = false; foreach (const Waypoint* tpt, header->waypoint_list) { @@ -1441,7 +1441,7 @@ void KmlFormat::kml_waypt_pr(const Waypoint* waypointp) const void KmlFormat::kml_track_hdr(const route_head* header) const { computed_trkdata td = track_recompute(header); - if (header->rte_waypt_ct() > 0 && (export_lines || export_points)) { + if (!header->rte_waypt_empty() && (export_lines || export_points)) { kml_output_header(header, &td); } } @@ -1453,7 +1453,7 @@ void KmlFormat::kml_track_disp(const Waypoint* waypointp) const void KmlFormat::kml_track_tlr(const route_head* header) { - if (header->rte_waypt_ct() > 0 && (export_lines || export_points)) { + if (!header->rte_waypt_empty() && (export_lines || export_points)) { kml_output_tailer(header); } } diff --git a/osm.cc b/osm.cc index 5e3691d0e..91365ef95 100644 --- a/osm.cc +++ b/osm.cc @@ -780,7 +780,7 @@ OsmFormat::osm_waypt_disp(const Waypoint* waypoint) void OsmFormat::osm_rte_disp_head(const route_head* route) { - skip_rte = route->rte_waypt_ct() <= 0; + skip_rte = route->rte_waypt_empty(); if (skip_rte) { return; diff --git a/ozi.cc b/ozi.cc index 83d5e3a61..14473ac8a 100644 --- a/ozi.cc +++ b/ozi.cc @@ -608,7 +608,7 @@ ozi_parse_track(int field, const QString& str, Waypoint* wpt_tmp, char* trk_name break; case 2: /* new track flag */ - if ((str.toInt() == 1) && (trk_head->rte_waypt_ct() > 0)) { + if ((str.toInt() == 1) && !trk_head->rte_waypt_empty()) { trk_head = new route_head; track_add_head(trk_head); if (trk_name) { diff --git a/position.cc b/position.cc index 23ccd3381..4d2d0695d 100644 --- a/position.cc +++ b/position.cc @@ -124,7 +124,7 @@ void PositionFilter::position_runqueue(WaypointList* waypt_list, int qtype) void PositionFilter::position_process_any_route(const route_head* rh, int type) { - if (rh->rte_waypt_ct() != 0) { + if (!rh->rte_waypt_empty()) { cur_rte = const_cast(rh); position_runqueue(&cur_rte->waypoint_list, type); cur_rte = nullptr; diff --git a/trackfilter.cc b/trackfilter.cc index 5de246446..b966a9355 100644 --- a/trackfilter.cc +++ b/trackfilter.cc @@ -183,7 +183,7 @@ QDateTime TrackFilter::trackfilter_get_last_time(const route_head* track) void TrackFilter::trackfilter_fill_track_list_cb(const route_head* track) /* callback for track_disp_all */ { - if (track->rte_waypt_ct() == 0) { + if (track->rte_waypt_empty()) { track_del_head(const_cast(track)); return; } @@ -272,7 +272,7 @@ void TrackFilter::trackfilter_pack_init_rte_name(route_head* track, const gpsbab // Uggh. strftime format exposed to user. gpsbabel::DateTime dt; - if (track->rte_waypt_ct() == 0) { + if (track->rte_waypt_empty()) { dt = default_time; } else { auto* wpt = track->waypoint_list.front(); @@ -392,7 +392,7 @@ void TrackFilter::trackfilter_merge() } } - if (master->rte_waypt_ct() == 0) { + if (master->rte_waypt_empty()) { track_del_head(master); track_list.clear(); } @@ -733,7 +733,7 @@ void TrackFilter::trackfilter_range() } } - if (track->rte_waypt_ct() == 0) { + if (track->rte_waypt_empty()) { track_del_head(track); it = track_list.erase(it); } else { -- 2.30.2